# -*- coding:utf-8 -*-
class Solution:
    def reverse(self, x):
        """
        :type x: int
        :rtype: int
        """
        if x < -2147483648 or x > 2147483647:
            return 0
        num = str(x)
        numlist = list(num)
        if numlist[0] == '-':
            num = reserveminus(numlist)
        else:
            num = reservenum(numlist)
        if int(num) < -2147483648 or int(num) > 2147483647:
            return 0
        return int(num)

def reserveminus(numlist):
    """
    倒置负数
    
    :param numlist: 
    :return: 
    """
    length = len(numlist)
    b = []
    b.append(numlist[0])
    for i in numlist[:0:-1]:
        b.append(i)
    return ''.join(b)

def reservenum(numlist):
    """
    倒置正数
    
    :param numlist: 
    :return: 
    """
    length = len(numlist)
    b = []
    for i in numlist[::-1]:
        b.append(i)
    return ''.join(b)

a = Solution()
b = a.reverse(123)
print(b)